package org.pearl.boot.redis.pub;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * Created by TD on 2021/5/12
 */
@Component
public class PubMsgTask {

    @Autowired
    RedisTemplate<String, Object> redisTemplate;

    /**
     * 每秒向redis-channel同调发送一Hello World
     */
    //@Scheduled(cron = "* * * * * ?")
    public void pubMsg() {
        System.out.println("redisTemplate正在发送消息");
        redisTemplate.convertAndSend("redis-channel", "Hello World");
    }
}
